/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Model;

import Common.Constant;
import Helper.CategoryHelper;
import java.util.ArrayList;
import javax.swing.table.AbstractTableModel;

/**
 *
 * @author KIENLT
 */
public class CategoryModel extends AbstractTableModel{
    ArrayList<CategoryHelper> CategoryList;
    
    private final String colunmsName[] = { Constant.getBundle().getString("Id"), Constant.getBundle().getString("Cname"), Constant.getBundle().getString("Sname"), Constant.getBundle().getString("Description") };
    private final Class columnsClass[] = { String.class, String.class, String.class, String.class };
    
    public CategoryModel(ArrayList<CategoryHelper> CategoryList){
        this.CategoryList = CategoryList;
    }
    
    @Override
    public int getRowCount() {
        return CategoryList.toArray().length;
    }

    @Override
    public int getColumnCount() {
        return colunmsName.length;
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        switch(columnIndex){
            case 0 : 
                return CategoryList.get(rowIndex).getId();
            case 1 : 
                return CategoryList.get(rowIndex).getName();
            case 2 :
                return CategoryList.get(rowIndex).getSupplierName();
            case 3 :
                return CategoryList.get(rowIndex).getDescription();
            default: 
                return null;
        }
    }
    
    @Override
    public String getColumnName(int icol){
        return colunmsName[icol];
    }
    
    @Override
    public Class getColumnClass(int icol){
        return columnsClass[icol];
    }
}
